<?php
 class Picturehomes extends CI_Model{
 function __construct(){
        parent::__construct();
    }
    
    /**
     * Get list product index
     * @author phuc.duong
     * @return array
     */
    public function getListIndex(){
       $this->db->limit(4);
       $this->db->order_by('CreatedDate', 'DESC');       
       $query = $this->db->get('picture_homes');
       return $query->result_array(); 
    }
    
    /**
     * Get list product for product list 
     * @author phuc.duong
     */
    public function getListProduct($cateId, $page = 1){
       $this->db->from('picture_homes');      
       $query = $this->db->get();        
       return $query->result_array();
    }
    
    /**
     * Get product
     * @author phuc.duong
     */
    public function getPicture($productId){
       $query = $this->db->get_where('picture_homes', array('PictureHomeId' => $productId));
       return $query->row_array();
    }
    
 /**
     * edit function in config
     * @author phuc.duong
     */
    public function edit($data, $productId){
        $data = $this->_convertData($data);
        return $this->db->update('picture_homes', $data, array('PictureHomeId' => $productId));
    }
    
 /**
     * Convert data array to array of product
     * @author phuc.duong
     */
    private function _convertData($data){
        $res = array();
        $arr = array('PictureName', 'Title', 'Summary', 'PictureLink');
        foreach($arr as $item){
            if(isset($data[$item])){
                $res[$item] = $data[$item];
            }
        }
        //set default value        
        return $res;
    }
    
 }